# Maintainer: David Runge <dvzrv@archlinux.org>

_name=MediathekView
pkgname=mediathekview
pkgver=14.0.0
pkgrel=1
pkgdesc="Access the Mediathek of many German TV stations"
arch=(any)
url="https://github.com/mediathekview/mediathekview"
license=(GPL-3.0-or-later)
_java_version=21
depends=(
  bash
  hicolor-icon-theme
  java-runtime=$_java_version
  xdg-user-dirs
)
makedepends=(
  maven
  strip-nondeterminism
)
conflicts=(mediathek)
provides=(mediathek)
replaces=(mediathek)
optdepends=(
  'libnotify: to use desktop notifications'
  'mplayer: for recording streams'
  'vlc: for stream playback'
)
source=(
  $pkgname-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz
  de.$pkgname.$_name.desktop
  $pkgname.sh
)
sha512sums=('e97844b4a06dbe42603d55854528b446638a4c0b830f824e7092c19ec2a7d308378f05887d2d0636ded48ec51354b8b2084448bf55778a7d5e31f1d145e030f2'
            '24a94a078180aca7c50ed7763ef4806c116c27f901f644ef570ee413ffc3ac795b5ebd24d696a9b2ec426e7c9b6eaf8a8b22addb5ac7c9fe9700f7c04305f64b'
            'a80983f3c09c196d3b78f623ba23b0d3da0da1bbbfc184ec90121b2a3c45937f9d0a9a1faca7a174b7a527e7d4c172bfab0973dd4d1e4ad8eb6206b3a3c65ca5')
b2sums=('a24308a98714b05d8df34bf06d64e3854ed9b826276b0ea576c23cebdf2ffd47139c003a9d8fdd12a87cf47191b50b63c1e2e66a1e141c2bc07b8a22b5a312c9'
        '6dbcdea2918009621fc132b4ff1056ef79f06e27c3299b69ccd7e3cb2b093e3a2a5f76acd6b1ab62689edd867ac1650f61bf829f2a1c575835d31e117d9b9ae5'
        '1243906e791489fb8a5abc7cd220b744259d43380ea1d95bf3fb454929f22f044d45a9f5f147033749e649f8d9760d69d5809eaa3f27223832fe5577bd6a7dcb')

prepare() {
  # set java version for wrapper script
  sed "s/JAVA_VERSION/$_java_version/" $pkgname.sh > $pkgname
}

build() {
  cd $_name-$pkgver
  ./mvnw clean install
  # Timestamps in JAR files generated by Maven do not honour SOURCE_DATE_EPOCH
  # (https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318)
  find . -type f -iname "*.jar" -exec strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" {} \;
}

package() {
  local _size

  cd $_name-$pkgver
  # jar
  install -vDm 644 target/$_name.jar -t "$pkgdir/usr/share/java/$pkgname/"
  # script
  install -vDm 755 ../$pkgname -t "$pkgdir/usr/bin/"
  # XDG desktop file
  install -vDm 644 ../de.mediathekview.$_name.desktop -t "$pkgdir/usr/share/applications/"
  # icons
  for _size in 16 32 48 128; do
    install -vDm 644 target/${_name}@x$_size.png "$pkgdir/usr/share/icons/hicolor/${_size}x$_size/apps/$pkgname.png"
  done
  install -vDm 644 res/$_name.svg -t "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  # docs
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
